package com.socketeg.demo.myThread;

import java.io.BufferedReader;
import java.io.IOException;


/**
 * 循环读取socket 输入流中的消息
 */
public class Readmessage extends Thread {
    BufferedReader bufferedReaderSocket;

    public Readmessage(BufferedReader bufferedReaderSocket) {
        this.bufferedReaderSocket = bufferedReaderSocket;
    }

    @Override
    public void run() {
        try {
            while (true) {
                String echo = bufferedReaderSocket.readLine();
                // 打印输出内容
                if (echo != null) {
                    System.out.println(echo);
                }
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            try {
                bufferedReaderSocket.close();
            } catch (IOException e) {
                System.out.println(e.getMessage());
            }
        }
    }


}
